package th.go.drr.gps.dao;

import org.apache.log4j.Logger;

import org.hibernate.HibernateException;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import th.go.drr.gps.dao.h.UserDAOHandler;
import th.go.drr.gps.domain.Usr;
import th.go.drr.gps.persistance.HibernateUtil;
@Repository
public class UsrDAO extends JpaTemplate<Usr> implements UserDAOHandler {

	private static Logger logger = Logger.getLogger(UsrDAO.class);

	@Override
	public Usr findByName(final String uname) {
		Usr u = null;		
		try {
			u = (Usr) HibernateUtil.getSession().createCriteria(Usr.class)
					.add(Restrictions.eq("username", uname)).uniqueResult();
		} catch (HibernateException e) {
			logger.error("not found :" + uname);
		}
		return u;
	}

}
